<?php


class Departamento
{
	public function __construct() {
		exit('Init function is not allowed');
	}

	public static function drawSelectedDepartamento($selectedDepartamento)
	{

		$con = Database::connect();
		$query = "SELECT * FROM tbl_departamento ORDER BY id_departamento";
		$stmt = $con->prepare( $query );
		$stmt->execute();

		$num = $stmt->rowCount();

		if($num>0){

			while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
				//exraer row

				extract($row);

				if($id_departamento == $selectedDepartamento){
					echo '<option  value="'.$id_departamento.'" selected>'.$nombre_departamento.'</option>';
				}else{
					echo '<option  value="'.$id_departamento.'">'.$nombre_departamento.'</option>';
				}

			}

		}
	}

}




class Municipio
{
	public function __construct() {
		exit('Init function is not allowed');
	}

	public static function drawSelectedMunicipio($selectedMunicipio,$selectedDepartamento)
	{

		$con = Database::connect();
		$query = "select id_municipio, nombre_municipio from tbl_municipio  where tbl_departamento_id_departamento = '$selectedDepartamento'";
		$stmt = $con->prepare( $query );
		$stmt->execute();

		$num = $stmt->rowCount();

		if($num>0){

			while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
				//exraer row

				extract($row);

				if($id_municipio == $selectedMunicipio){
					echo '<option  value="'.$id_municipio.'" selected>'.$nombre_municipio.'</option>';
				}else{
					echo '<option  value="'.$id_municipio.'">'.$nombre_municipio.'</option>';
				}

			}

		}
	}

}


?>